//
//  AppDelegate.swift
//  UIKitApp
//
//  Created by changlei on 2021/11/4.
//
//

import UIKit


@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        if (window == nil) {
            window = UIWindow(frame: UIScreen.main.bounds)
        }
        let newAppearance = UINavigationBarAppearance()
        newAppearance.configureWithDefaultBackground()

        let appearance = UINavigationBar.appearance()
        appearance.scrollEdgeAppearance = newAppearance
        appearance.standardAppearance = newAppearance

        window!.rootViewController = UINavigationController(rootViewController: LaunchController())
        window!.makeKeyAndVisible()
        return true
    }
}

extension AppDelegate {
    static let shared: UIApplication = UIApplication.shared

    static let `default` = shared.delegate as! AppDelegate

    var windowScene: UIWindowScene? {
        AppDelegate.default.window?.windowScene
    }

    var statusBarManager: UIStatusBarManager? {
        windowScene?.statusBarManager
    }

    var statusBarFrame: CGRect? {
        statusBarManager?.statusBarFrame
    }

    var navigationViewController: UINavigationController? {
        window?.rootViewController as? UINavigationController
    }

    var topViewController: UIViewController? {
        navigationViewController?.topViewController
    }
}
